<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index.jsp</title>
<link rel="stylesheet" type="text/css" href="../css/user.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/jquery.validate.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$('table input[type!=button][type!=submit]').css('display','none');
		$('table textarea').css('display','none');
		
		$('#saveBtn').attr('disabled','disabled');
		$('#editBtn').click(function(){
			$('table div').css('display','none');
			$('table textarea').css('display','block');
			$('table input[type!=button]').css('display','block');
			$('#saveBtn').removeAttr('disabled')
			
			$('#editBtn').attr('disabled','disabled');
		});
		
		$('#saveBtn').click(function(){
			if($('#loginForm').valid()){
				var formValue = $('#loginForm input[type!=button]');
				var params = {};
				formValue.each(function(){
					params[this.name] = this.value; 
				});
				params['companyIntroduction'] = $('textarea[name=companyIntroduction]').val();
				$.post('./update.do',params,function(user,status){
					if(status == 'success'){
						$('table div').css('display','block');
						$('table input[type!=button][type!=submit]').css('display','none');
						$('#saveBtn').attr('disabled','disabled');
						$('table textarea').css('display','none');
						$('#editBtn').removeAttr('disabled')
						for(key in user){
							$('input[name='+key+']').val(user[key]);
							$('input[name='+key+']').prev('div').html(user[key]);
						}
						$('textarea[name=companyIntroduction]').val(user.companyIntroduction);
						$('textarea[name=companyIntroduction]').prev('div').html(user.companyIntroduction);
					}
				});
			}
		});
		
		$('#profileBtn').click(function(){
			window.location.href = 'edit.do';
		});
		$('#viewAnswerBtn').click(function(){
			window.location.href = 'view-answer-list.do';
		});
		$('#newQuestionBtn').click(function(){
			window.location.href = '../question/newQuestion.do';
		});
	});
</script>
</head>

<body>
	<center>
		<form action="./update.do" method="post" id='loginForm'>
			<div class='photo'>
				<span><img alt="" src="../image/3448.png" /></span>
				<span>
					<div>${profile.username }</div>
					<div>性别：${profile.gender?'男':'女' }</div>
				</span>
			</div>
			<table class='dataintable'>
				<tbody>
					<tr>
						<th><div>${profile.name }</div>
						<input value='${profile.name }' placeholder='名字' name='name' required maxlength=15 /></th>
					</tr>
					<tr>
						<th><div>${profile.age }</div>
						<input value='${profile.age }' placeholder='年龄' name='age' max=100 min=0 required /></th>
					</tr>
					<tr>
						<th><div>${profile.company }</div>
						<input value='${profile.company }' placeholder='所在企业' name='company' maxlength = 100/></th>
					</tr>
					<tr>
						<th><div>${profile.title }</div>
						<input value='${profile.title }' placeholder='职位' name='title' maxlength=50/></th>
					</tr>
					<tr>
						<th><div>${profile.profession }</div>
						<input value='${profile.profession }' placeholder='所属行业' name='profession' maxlength=500 /></th>
					</tr>
					<tr>
						<th><div>${profile.companyIntroduction }</div>
							<textarea placeholder='企业业务介绍'  maxlength=500 
								name='companyIntroduction'>${profile.companyIntroduction }</textarea>
						</th>
					</tr>
					<tr>
						<th align="right">
							<input type='button' value='修改' id='editBtn'/>
							<input type='button' value='提交' id='saveBtn'/>
							<input type='hidden' value='${profile.uid }' name='uid'/>
						</th>
					</tr>
				</tbody>
			</table>
			<div class='foot'>
				<span><input type='button' value='我要提问' id='newQuestionBtn' /></span>
				<span><input type='button' value='查看回答' id='viewAnswerBtn' class="${hasNewAnswer?'news':'' }"/></span>
				<span><input type='button' value='我的资料' id='profileBtn'/></span>
			</div>
		</form>
	</center>
</body>
</html>
